package Demo5;

public class ThreadYield {
    public static void main(String[] args) {
        MyYield yield = new MyYield();

        new Thread(yield,"a").start();
        new Thread(yield,"b").start();
    }
}

class MyYield implements Runnable {
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"线程开始执行");
        Thread.yield(); // 线程礼让
        System.out.println(Thread.currentThread().getName()+"线程结束执行");
    }
}
